package com.blb.mapper;

import com.blb.entity.ProductionLine;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author lifeng
 * @since 2019-11-15
 */
public interface ProductionLineMapper extends BaseMapper<ProductionLine> {

    /**
     * 通过生产线名称查找生产线   生产线查重
     * @param productionName
     * @param companyId
     * @return
     */
    @Select("select * from t_production_line where production_name = #{productionName} and company_id = #{companyId}")
    ProductionLine getProductionName(String productionName,String companyId);

    /**
     * 查看是否有此产线
     * @param companyId
     * @return
     */
    @Select("select * from t_production_line where company_id = #{companyId} and id = #{id}")
    List<ProductionLine> findId(int id ,String companyId);

    /**
     * 查看公司所有产线
     * @param companyId
     * @return
     */
    @Select("select * from t_production_line where company_id = #{companyId}")
    List<ProductionLine> allProductionLine(String companyId);

    /**
     * 删除公司
     * @param id
     * @param companyId
     */
    @Delete("DELETE FROM t_production_line WHERE id = #{id} and company_id = #{companyId}")
    void remove(String id,String companyId);

    /**
     * 修改生产线
     * @param productionLine
     */
    @Update("update t_production_line set production_name = #{productionName},production_capacity" +
            " = #{productionCapacity},principal = #{principal}," +
            "num = #{num},state = #{state},remark = #{remark} WHERE id = #{id} and company_id = #{companyId}")
    void updProductionLineMapper(ProductionLine productionLine);
    /**
     * 查看公司所有的生产线名称
     * @return
     */
    @Select("select production_name from t_production_line where company_id = #{companyId}")
    List<String> findProductionLineName(String companyId);

    /**
     * 根据公司id查看的生产线名称
     * @return
     */
    @Select("select id from t_production_line where production_name = #{productionName} and company_id = #{companyId}")
    Integer findProductionLineIdByName(String productionName,String companyId);
}
